When we `add u v`, we must update our adjacency list. Since friendships are mutual (undirected), we must update two lists.
Guidance for Step 2
- Mutual Friendship: If `u` is friends with `v`, then `v` is friends with `u`. You must add `v` to `adj[u]` AND add `u` to `adj[v]`.
- Avoid Duplicates: To prevent `[1, 1]` in a friend list, check if a friendship already exists before adding it.
- Your Task: Fill in the blanks to correctly add a friendship.
...
if op == "add":
u, v = int(parts[1]), int(parts[2])
# --- BLANK 1 ---
# We only add the friendship if they aren't already friends.
if _____________________:
# --- BLANK 2 ---
# Undirected graph: add edge in both directions
_________________
_________________
elif op == "degree":
...
Copied!